/**
@author		Jong Min, Lee
@date		  10/01/2014
@breif		study class 

copyright(c) Tae Young Soft. All right reserved. 2014
*/
#pragma once

#include <vector>

#include "Taurus_Util/Macros.h"
#include "Taurus_DcmData/Defines.h"

//forward declarations
class CStudySet;
class CDcmStudy;
class CDcmSeries;
class CSeries;

/**
@brief		study class
*/
class TAURUS_DCMDATA_EXPORT CStudy
{
private:
  /**
  @brief		default constructor
  */
  CStudy(); 

  DISALLOW_COPY_AND_ASSIGN(CStudy);

public:
  friend class CStudyProducer;

  /**
  @brief		destructor
  */
  ~CStudy();

  /**
  @brief		get parent study set
  @return		pointer to parent study set if study has it, nullptr if not
  */
  inline CStudySet* getParent() const
  {
    return m_theParent;
  }

  /**
  @brief		set parent study set
  @param		parent pointer to study set to be parent
  */
  inline void setParent(CStudySet* parent)
  {
    m_theParent = parent;
  }

  /**
  @brief		get study key
  @return		null-terminiated string represents study key
  */
  const TCHAR* getKey() const;

private:
  /**
  @brief		initialize this
  */
  void init();

  /**
  @brief		destroy this. this function should be only used in dsetructor
  */
  void destroy();

  /**
  @brief		add series
  @param		series pointer to series to be added
  @return		ERROR_SUCCESS upon success, an error code otherwise
  */
  DWORD addSeries(CSeries* series);

  
  /**
  @brief		remove all series
  */
  void removeAllSeries();

  /**
  @brief		remove all image series
  */
  void removeAllImageSeries();

  /**
  @brief		remove all none image series
  */
  void removeAllNoneImageSeries();

  /**
  @brief		clear array of pointers to series
  */
  void clearSeriesArray(std::vector<CSeries*>& series);


private:
  //pointer to dcm study
  CDcmStudy* m_theDcmStudy;

  //pointer to parent study set
  CStudySet* m_theParent;

  //image series
  std::vector<CSeries*> m_theImageSeries;

  //none image series
  std::vector<CSeries*> m_theNoneImageSeries;
};

/**
@brief		study producer class for study
*/
class TAURUS_DCMDATA_EXPORT CStudyProducer
{
public:
  /**
  @brief		create a new study by using dcm study
  @param		dcmStudy pointer to dcm study to be based
  @param    parent pointer to study set to be parent
  @param    outStudy variable in which new study is stored
  @return		ERROR_SUCCESS if succeeds, an error code otherwise
  */
  static DWORD produce(CDcmStudy* dcmStudy,
                       CStudySet* parent,
                       CStudy* outStudy);

  /**
  @brief		creat a new study by using dcm study
  @param		dcmStudy pointer to dcm study to be based
  @param    series pointers to series to be belong to new study
  @param    numSeries the number of pointers to series to be belong to new study
  @param    parent pointer to study set to be parent
  @param    outStudy variable in which pointer to new study is stored
  @return		
  */
  static DWORD produce(CDcmStudy* dcmStudy,
                       CSeries** series,
                       const unsigned int numSeries,
                       CStudySet* parent,
                       CStudy*& outStudy);

private:
    /**
  @brief	  Attach dcm study to study. this method only initialize data with study, not its series	
  @param		pStudy pointer to study
  @param    pDcmStudy pointer to dcm study to be attached
  @param    pParent pointer to study set to be parent
  @return		ERROR_SUCCESS upon succes, an error code otherwise
  */
  static DWORD attachDcmStudy(CStudy*    study,
                              CDcmStudy* dcmStudy,
                              CStudySet* parent);
};